<template>
    <image :src="src" mode="widthFix" :style="imageStyle" @click="handleDoubleClick" />
</template>

<script>
export default {
    props:["src"],
    emits:[""],
    data() {
        return {
            lastClickTime: 0,
            rotateDeg: 0,
            // 结合历史CSS变量方案
            cssVars: {
                '--transition-duration': '0.3s'
            }
        }
    },
    computed: {
        imageStyle() {
            return {
                ...this.cssVars,
                transform: `rotate(${this.rotateDeg}deg)`,
                transition: `transform var(--transition-duration) ease`,
                position: "relative",
                zIndex: 99,
                width:"135rpx",
                height:"135rpx",
            }
        }
    },
    methods: {
        handleDoubleClick() {
            const now = Date.now()
            if (now - this.lastClickTime < 300) {
                this.rotateDeg += 90
                // 重置角度超过360度时
                if (this.rotateDeg >= 360) this.rotateDeg = 0
            }
            this.lastClickTime = now
        }
    }
}
</script>

<style scoped>
image {
    width: 300px;
    height: 200px;
    display: block;
    margin: 0 auto;
}
</style>